package J5_10;

import java.util.*;

public class test {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while (t-- > 0) {
            int h = in.nextInt(), a = in.nextInt(), H = in.nextInt(), A = in.nextInt();
            if (a >= H) {
                System.out.println(-1);
                continue;
            }
            int everA = (H - 1) / a * A;
            int res = h / everA;
            if (h % everA == 0) {
                System.out.println(res - 1);
            } else {
                System.out.println(res);
            }
        }
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] strs = new String[n];
        for (int i = 0; i < n; i++) {
            char[] ch = in.next().toCharArray();
            Arrays.sort(ch);
            strs[i] = new String(ch);
        }
        Arrays.sort(strs);
        int res = 1;
        for (int i = 1; i < n; i++) {
            if (strs[i].equals(strs[i-1])) {
                continue;
            }
            res++;
        }
        System.out.println(res);
    }


    public int citys (ArrayList<ArrayList<Integer>> m) {
        Map<Integer, Set<Integer>> map = new HashMap<>();
        for (int i = 0; i < m.size(); i++) {
            for (int j = 0; j < m.get(0).size(); j++) {
                if (m.get(i).get(j) == 1) {
                    Set<Integer> set = map.getOrDefault(i, new HashSet<>());
                    set.add(j);
                    map.put(i, set);
                }
            }
        }
        boolean[] visited = new boolean[m.size()];
        int res = 0;
        for (int i = 0; i < m.size(); i++) {
            if (!visited[i]) {
                visited[i] = true;
                bfs(visited, i, map);
                res++;
            }
        }
        return res;

    }

    private void bfs(boolean[] visited, int i, Map<Integer, Set<Integer>> map) {
        Queue<Integer> queue = new ArrayDeque<>();
        queue.offer(i);
        while (!queue.isEmpty()) {
            int t = queue.poll();
            for (int a : map.get(t)) {
                if (!visited[a]) {
                    queue.add(a);
                    visited[a] = true;
                }
            }
        }
    }

    public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }
    public boolean IsBalanced_Solution (TreeNode pRoot) {
        if (pRoot == null) {
            return true;
        }
        int left = getDepth(pRoot.left);
        int right = getDepth(pRoot.right);
        if (Math.abs(left - right) > 1) return false;
        return IsBalanced_Solution(pRoot.left) && IsBalanced_Solution(pRoot.right);
    }

    private int getDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(getDepth(root.left), getDepth(root.right)) + 1;
    }



    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] arr = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j] = in.nextInt();
            }
        }
        int[][] sum =new int[n + 1][n + 1];
        int[][][][] dp =new int[n + 1][n + 1][n + 1][n + 1];
        int max = Integer.MIN_VALUE;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                sum[i][j] = sum[i-1][j] + sum[i][j-1] + arr[i-1][j-1] - sum[i-1][j-1];
                for (int i1 = i; i1 > 0; i1--) {
                    for (int j1 = j; j1 > 0; j1--) {
                        dp[i1][j1][i][j] = sum[i][j] - sum[i1 - 1][j] - sum[i][j1 - 1] + sum[i1-1][j1-1];
                        max = Math.max(max, dp[i1][j1][i][j]);
                    }
                }
            }
        }
        System.out.println(max);
    }


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        char[] ch = in.next().toCharArray();
        int n1 = 0, n0 = 0;
        int l = 0, r = 0, cur0 = 0, cur1 = 0;
        for (int i = 0; i < n; i++) {
            if (ch[i] == '0') {
                if (r < n / 2) {
                    cur0++;
                    r++;
                } else {
                    n0++;
                }
            }else {
                if (r < n / 2) {
                    cur1++;
                    r++;
                } else {
                    n1++;
                }
            }
        }
        int res = 0;
        int t = n;
        while (t-- > 0) {
            if (cur0 == n0 && cur1 == n1) {
                res++;
            }
            if (ch[l] == '0') {
                cur0--;
                n0++;
            } else {
                cur1--;
                n1++;
            }
            if (ch[r] == '0') {
                cur0++;
                n0--;
            } else {
                cur1++;
                n1--;
            }
            l++;
            r = (r + 1) % n;
        }
        System.out.println(res);
    }
}
